<?php
/**
 * @title 55. 跳跃游戏 - 动态规划
 * @author start2004
 */

class Solution {

    /**
     * @param Integer[] $nums
     * @return Boolean
     */
    function canJump($nums) {
        /**
         * @since 2020-07-23 遍历
         */
        $prev = 0;
        for($i=0, $iMax=count($nums)-2; $i<=$iMax; $i++){
            /**
             * @since 2020-07-23 上个点到这里, 能否延长的最大长度
             */
            $prev = max($prev, $nums[$i]);

            /**
             * @since 2020-07-23 无法再前进
             */
            if($prev == 0){
                return false;
            } else {
                $prev--;
            }
        }

        /**
         * @return
         */
        return true;
    }
}




/**
 * @url http://127.0.0.1/leetcode/202007/2020.07.23_5.php
 */
$datas = [
    [2,3,1,1,4],
    [3,2,1,0,4],
];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    var_dump($data);

    $obj = new Solution();
    $result = $obj->canJump($data);
    var_dump($result);
    echo str_repeat("<br>", 3);
}
$xhprof->end();
